// set function formatTime to filter
import {
    timestampToFormatTime,
    formatTimeToTimestamp
} from '/src/utils/index.js'

export {formatTime} from '/src/utils/index.js'

export function useFormatTimeHook() {
    /**
     * 时间戳到格式化时间
     * {{item.createTime|filterTimestampToFormatTime('MM-DD dddd')}}
     * @param {*} time
     * @param {*} cFormat
     */
    function filterTimestampToFormatTime(time, cFormat) {
        if (!cFormat) {
            cFormat = 'YYYY-MM-DD HH:mm'
        }
        if (!time || time == 0) {
            return ''
        }
        return timestampToFormatTime(time, cFormat)
    }

    /** 格式化时间到时间戳 */
    function filterFormatTimeToTimestamp(format) {
        return formatTimeToTimestamp(format)
    }

    /** 用户头像的占位图标 */
    function filterUserLazyImg(value) {
        return {
            src: value,
            error: () => import('/src/assets/img/head.png'),
            loading: () => import('/src/assets/img/loading.gif')
        }
    }

    /**
     * wk 10.0 iconfont 前缀
     */
    function wkIconPre(name) {
        console.log("name", name)
        return name.startsWith('wk') ? name : `wk wk-${name}`
    }

    return {
        filterTimestampToFormatTime, filterFormatTimeToTimestamp, filterUserLazyImg, wkIconPre
    }
}

